package com.web.kongjian.tag;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.base.user.entity.Member;
import com.base.user.service.MemberService;
import com.mysteel.core.SpringContext;
import com.web.user.member.utils.CookieUtils;

import cn.mysteel.util.ObjectUtils;
import cn.mysteel.util.StringUtils;
import cn.mysteel.util.URLEncoder;

public class UserInfoTag
{
	private MemberService memberService;
	public UserInfoTag()
	{
		memberService = (MemberService)SpringContext.getBean ("memberService");
	}
	
	public Map<String, Object> getUserInfo(HttpServletRequest request)
	{
	
		Map<String, Object> returnMap = new HashMap<String,Object>();
		
		String memberId = CookieUtils.getCookieValue (request ,"member_id");
		String nickName = CookieUtils.getCookieValue (request ,"nickName");
		String login_type_id = CookieUtils.getCookieValue (request ,"login_type_id");
		
		if(StringUtils.notNull (memberId)&&StringUtils.notNull (nickName))
		{
			returnMap.put ("memberId" ,memberId);
			nickName = URLEncoder.decode (nickName);
			returnMap.put ("nickName" ,nickName);
			returnMap.put ("login_type_id" ,login_type_id);
		}
		
		return returnMap;
	}
	
	
	public Map<String, Object> getUserInfoBySee(HttpServletRequest  request)
	{
		long memberId = Long.parseLong (request.getParameter ("memberId"));
		
		Map<String, Object> returnMap = new HashMap<String,Object>();
		
		Member m = memberService.getMemberById (memberId);
		
		if(ObjectUtils.notNull (m))
		{
			returnMap.put ("nickName" ,m.getNickName ());
			returnMap.put ("memberId" ,m.getId ());
		}
		
		return returnMap;
	}
	
	
	public Member getMemberById(long id)
	{
		
		return memberService.getMemberById (id); 
	}
	
}
